package com.yqy.controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;


@ControllerAdvice//将当前类标识为异常处理的组件
public class ExceptionAnnotationTestController {
    @ExceptionHandler(NullPointerException.class)//指定要处理的异常类型
    public String handleNullPointerException(Throwable exception, Model model){
        model.addAttribute("exception", exception);//将异常信息共享到请求域
        return "error";
    }
}
